/*******************************************************************************
 * Copyright (c) 2011 squid.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     squid - initial API and implementation
 ******************************************************************************/
package com.google.code.cubeirc.basequeue;

import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;

import lombok.Getter;
import lombok.Setter;

import com.google.code.cubeirc.base.IBase;

public final class BaseQueue {

	@Getter @Setter
	private static ConcurrentLinkedQueue<IBase> components = new ConcurrentLinkedQueue<IBase>();
	
	
	/**
	 * Add base to component list
	 * @param component
	 */
	public static void addComponent(IBase component)
	{
		getComponents().add(component);
	}
	
	/**
	 * Remove component from component list
	 * @param component
	 */
	public static void removeComponent(IBase component)
	{
		getComponents().remove(component);
	}
	
	/**
	 * Close all bases
	 */
	public static void Close()
	{
		Iterator<IBase> it =  getComponents().iterator();
		while(it.hasNext())
		{
			IBase li = it.next();
			
			Boolean closed = false;
			while (!closed)
				closed = li.Close();				
		}
		
		System.exit(0);
	}
	
}
